/**
 * @author BoLiang
 */
if (typeof accedo === "undefined") {
	accedo = {};
}
if (typeof accedo.achievement === "undefined") {
	accedo.achievement = {};
}

accedo.achievement.achiCompareShow = {

	divLength: 0,
	divCtnNode: null,
	divInnNode: null,
	divContLoading: null,
	
	init: function() {
		this.divLength = accedo.achievement.achiShow.divLength; 
		this.divCtnNode = null;
		this.divInnNode = null;
		this.divContLoading = null;
	},
	
	
	recoverUserAchis: function() {
		var divInnNode = document.getElementById("divAchiShowInner");
		for(var achiCellNum = 0; achiCellNum < this.divLength; achiCellNum++) {
			var achiFriCell = document.getElementById("FriAchi" + achiCellNum); 
			divInnNode.removeChild(achiFriCell);
			
			var achiCell = document.getElementById(achiCellNum); 
			achiCell.className = "divAchiShowRecoverCell"; 
		}
	},
	
	initCompare : function(username, app_sn) {
		dwr.engine.setPreHook(this.preHook); 
		dwr.engine.setPostHook(this.postHook); 
		AchiService._path = "http://"
								+ accedo.achievement.config.serverIP + ":" 
								+ accedo.achievement.config.serverPort + "/" 
								+ accedo.achievement.config.pluginName + "/dwr";
		AchiService.getJsonAchisByAppsn(username, app_sn, this.initCompareCallback);
	},
	
	preHook : function() {
		// accedo.achievement.achiCompareShow.preInitHookFunc(); 
	},



	postHook : function() {
		// accedo.achievement.achiCompareShow.postInitHookFunc(); 
	},


	initCompareCallback: function(jsonData) {
		// var jsonData = eval("(" + data + ")");
		
		var divInnNode = document.getElementById("divAchiShowInner");
//		var divInnNode = accedo.achievement.achiCompareShow.divInnNode; 
		var topInterval = 0;
		for(var achiCellNum = 0; achiCellNum < accedo.achievement.achiCompareShow.divLength; achiCellNum++) {
			var achiCell = document.getElementById(achiCellNum); 
			
			divInnNode.removeChild(achiCell); 
			var achiFriCell = document.getElementById("FriAchi" + achiCellNum); 
			if (achiFriCell != null) {
				divInnNode.removeChild(achiFriCell); 
			}
			achiCell.className = "divAchiShowShrinkCell";
			
			topInterval = topInterval + 5;
			var divNode = document.createElement("div");
			divNode.id = "FriAchi" + achiCellNum;
			divNode.className = "divAchiCompareShowCell";
			divNode.style.top = topInterval + "px";
			
			var divTickNode = document.createElement("div");
			divTickNode.id = "divFriTick";
			divTickNode.innerHTML = "<img width=90% height=90% src='http://"
								+ accedo.achievement.config.serverIP + ":" 
								+ accedo.achievement.config.serverPort + "/" 
								+ accedo.achievement.config.pluginName + "/achiPlugin/achi-images/achiFriTick.png' />";

			if (jsonData.achis[achiCellNum].achi_state == "A") {
				divNode.appendChild(divTickNode);
			}
			
			
			divInnNode.appendChild(achiCell); 
			divInnNode.appendChild(divNode); 
		}
	},
	
	appendCompare: function(friendName, app_sn) {
		this.init(); 
		this.initCompare(friendName, app_sn); 
	},
};
